package com.dixon.worddayday.bo;

import com.dixon.worddayday.model.Customer;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

public class CustomerSession extends User {
    private Customer customer;

    public CustomerSession(Customer customer) {
        this(customer.getName(), customer.getPassword(), new ArrayList<>());
        this.customer = customer;
    }

    public CustomerSession(Customer customer, String role) {
        this(customer.getName(), customer.getPassword(), Arrays.asList(new SimpleGrantedAuthority("ROLE_" + role)));
        this.customer = customer;
    }

    public CustomerSession(String username, String password, Collection<? extends GrantedAuthority> authorities) {
        super(username, password, authorities);
    }

    public Customer getCustomer() {
        return customer;
    }

    public void setCustomer(Customer customer) {
        this.customer = customer;
    }
}
